package com.quwan.manager.controller;

import com.quwan.common.BaseController;
import com.quwan.common.result.ApiResult;
import com.quwan.common.result.PageResult;
import com.quwan.entity.TBanner;
import com.quwan.entity.TMemberRecommend;
import com.quwan.manager.service.BannerSystemService;
import com.quwan.manager.service.MemberRecommendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author laozhang
 * @date 2022/2/16
 */
@Api(tags = "后台会员推荐管理接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("mgr/memberRecommend")
public class MemberRecommendController extends BaseController {
    private final MemberRecommendService memberRecommendService;

    @ApiOperation(value = "会员推荐列表分页",notes = "<span style=\"color:red\">注意参数是否必填</span>",httpMethod = "POST")
    @PostMapping("recommendListPage")
    public ApiResult<PageResult<TMemberRecommend>> memberRecommendListPage(@RequestParam(defaultValue = "1") int page,
                                                                           @RequestParam(defaultValue = "10") int size,
                                                                           @ApiParam("真实姓名") @RequestParam(required = false) String realName,
                                                                           @ApiParam("会员昵称") @RequestParam(required = false) String nickName,
                                                                           @ApiParam("开始时间 格式：yyyy-MM-dd") @RequestParam(required = false) String beginTime,
                                                                           @ApiParam("结束时间 格式：yyyy-MM-dd") @RequestParam(required = false) String endTime) {
        PageResult<TMemberRecommend> res = memberRecommendService.getMemberRecommendListPage(page,size,realName,nickName,beginTime,endTime);
        return ApiResult.success(res);
    }

    @ApiOperation(value = "会员推荐列表",notes = "<span style=\"color:red\">注意参数是否必填</span>",httpMethod = "POST")
    @PostMapping("recommendList")
    public ApiResult<List<TMemberRecommend>> memberRecommendList(@ApiParam("真实姓名") @RequestParam(required = false) String realName,
                                                                 @ApiParam("会员昵称") @RequestParam(required = false) String nickName,
                                                                 @ApiParam("开始时间 格式：yyyy-MM-dd") @RequestParam(required = false) String beginTime,
                                                                 @ApiParam("结束时间 格式：yyyy-MM-dd") @RequestParam(required = false) String endTime) {
        List<TMemberRecommend> res = memberRecommendService.getMemberRecommendList(realName,nickName,beginTime,endTime);
        return ApiResult.success(res);
    }


    @PostMapping("addRecommend")
    @ApiOperation("增加会员推荐")
    public ApiResult addMemberRecommend(@ApiParam("会员id") @RequestParam(required = true) Integer mId,
                                        @ApiParam("真实姓名") @RequestParam(required = false) String realName,
                                        @ApiParam("会员昵称") @RequestParam(required = false) String nickName,
                                        @ApiParam("电话号") @RequestParam(required = false) String phone,
                                        @ApiParam("标签") @RequestParam(required = true) String label,
                                        @ApiParam("排序") @RequestParam(required = true) Integer sort){
        TMemberRecommend memberRecommend= new TMemberRecommend();
        memberRecommend.setMId(mId);
        memberRecommend.setRealName(realName);
        memberRecommend.setNickName(nickName);
        memberRecommend.setPhone(phone);
        memberRecommend.setLabel(label);
        memberRecommend.setSort(sort);
        memberRecommend.setAddTime(LocalDateTime.now());
        boolean success = memberRecommendService.addMemberRecommend(memberRecommend);
        if (success)
            return ApiResult.successMsg();
        else
            return ApiResult.failed();
    }


    @PostMapping("delRecommend")
    @ApiOperation("删除会员推荐（下架）")
    public ApiResult delMemberRecommend(@RequestParam(value = "id") Integer id){
        boolean success = memberRecommendService.delMemberRecommend(id);
        if (success)
            return ApiResult.successMsg();
        else
            return ApiResult.failed();
    }



}
